<template>
  <div class="loginShs">
    <navigationTar></navigationTar>
    <div class="shs_body">
      <manage_login></manage_login>
    </div>
  </div>
</template>


<script>
import { getNewtoken } from "@/request/api"
export default {
  name: "loginShs",
  components: {
    navigationTar: () => import("@/components/navigationTar.vue"),
    manage_login: () => import('@/components/manageLogin.vue'),
  },
  //挂载
  mounted() {
    //检测是否已经有管理员登录
    //有就直接跳转
    let _this = this;
    this.userinfo = JSON.parse(localStorage.getItem("userinfo")) || null;
    // console.log(this.userinfo);
    if (this.userinfo) {
      //有用户登录就有token 请求新的token
    //   console.log('usertoken1', localStorage.getItem("usertoken"));
      let obj = {
        user_rank: _this.userinfo.user_rank,
        token: localStorage.getItem("usertoken") || null
      }
      getNewtoken(obj)
        .then((resp) => {
        //   console.log(" resp?.data?", resp?.data);
          if (resp?.data?.code == 200) {
            localStorage.setItem(
              "usertoken",
              resp?.data?.token
            );
            return this.$confirm("管理员已登录是否跳转")
          } else {
            // _this.$message({ message: resp?.data.msg, type: "error" });
          }
        }).then(() => {
        //   console.log("登录的data", data);
          _this.$router.push({
            path: "/backStage/classlist",
          });
        })
        .catch((err) => {
          _this.$message({ message: err, type: "error" });
        });
    }
  }
};
</script>
<style>
.shs_body {
  position: relative;
  height: 100vh;
}
</style>
